$(document).ready(function () {
    /**
     * 页面初始化
     *     1. table
     *     2. select
     * */
    initTable();
    initEmployeeSelect();
    /*事件绑定*/
    $('#btnAdd').bind('click',btnAddClick);
    $('#basic').bind('change',basicChange)
    $('#sub').bind('change',subChange);
    $('#real').attr('disabled',true);

})


function subChange(){

     var post = parseInt($('#post').val());
     var sub = parseInt($('#sub').val());

     $('#real').val(post-sub);

}

function initEmployeeSelect() {

    $.each(normal.list,function (index,item) {
        var opt = $('<option></option>').val(item.id).text(item.name);

         $('#employeeForEdit').append(opt);
    })


}

function btnAddClick() {

    showBtnSave(true);

    $('#infoTitle').text("普通员工薪资——创建");

    $('#info').modal();
}
/***
 *  为添加或者修改窗体显示 保存按钮
 *     true 显示  添加-保存
 *     false 显示 修改-保存
 * */
function showBtnSave(isAdd) {
    $('#btnSaveForAdd').hide();
    $('#btnSaveForEdit').hide();

    if(isAdd){
        $('#btnSaveForAdd').show();
    }else {
        $('#btnSaveForEdit').show();
    }
}



function basicChange(){
    var basic = parseInt($('#basic').val())*0.8;
    $('#post').val(basic);
}


function initTable() {

    /**
     * 1. 模拟数据
     * 2. 列规范
     * */

     $('#list').bootstrapTable({
       /*  url:"http://test.org/salary/normal",*/
         url:"http://localhost:8088/salary/nor/list",
         columns:columns,
         pagination:true,
         pageSize:5,
         sidePagination:"client",
         toolbar:'#toolbar',
         singleSelect:true,
         clickToSelect:true
     })

}
var columns = [
    {
        checkbox:true
    },
    {
        title:"员工编号",
        field:"employee.code"
    },{
        title:"姓名",
        field:"employee.name"
    },{
         title:'部门',
          field:'employee.dept.name'
    },
    {
        field:"basicSalary",
        title:"基本工资"
    },
    {
         field:'postWage',
         title:'税后工资'
    },{
         field:'subSidy',
         title:'减除项目'
    },{
         title:'实发工资',
          formatter:function (val,row,index) {
             return row.postWage-row.subSidy;
          }
    }

]
